/**
 * 
 * @author Sunix
 * @date   2013-5-20
 * @Email  SunixSky@gmail.com
 * 
 */	
package view.components{
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	
	import scaleform.clik.controls.Button;
	import scaleform.clik.controls.Window;

	public class DialoguePanel extends Window{
		
		public var info:TextField;
		public var cancelBtn:Button;
		public var sureBtn:Button;



		public var sureFun:Function = null;
		public var sureParam:Array = null;
		public var cancelFun:Function = null;
		public var	cancelParam:Array = null;
		
		private var _message:String;

		public function DialoguePanel(){
			addEventListener(Event.ADDED_TO_STAGE,onAddedToStage);
		}
		
		public function set message(value:String):void{
			info.text = value;
			info.height = info.textHeight +5;
		}
		
		protected function onAddedToStage(event:Event):void{
			viewInit();
			eventInit();	
			setSize(300,200);
		}
		
		private function viewInit():void{
			info.autoSize = TextFieldAutoSize.NONE;
			info.wordWrap = true; //设置自动换行
			info.multiline = true; //允许多行
			info.width = 200;
			title = '提示';
		}
		
		private function eventInit():void{
			sureBtn.addEventListener(MouseEvent.CLICK,onSure);
			cancelBtn.addEventListener(MouseEvent.CLICK,onCancel);
		}
		
		protected function onCancel(event:MouseEvent):void{
			if(cancelFun)
				cancelFun.apply(null, cancelParam);
			super.onCloseButtonClick(event);
		}
		
		protected function onSure(event:MouseEvent):void{
			if(sureFun)
				sureFun.apply(null, sureParam);
			super.onCloseButtonClick(event);
		}
		
		override public function set title(value:String):void {
			if(!value)
				return;
			super.title = value;
		}
	}
}